<?php
	include("/../data.php");
	session_start();
	if(($_SESSION['db_is_logged_in'] == false) || ($_SESSION['profile'] != 'admin'))
		header("location:index.php");
	
	$pass = "";	
	
	$connect=mysql_connect($DatabaseServer,$DatabaseUsername,$DatabasePassword) or die("can't connect this database");
			mysql_select_db($DatabaseName,$connect);
			
    $sql="select * from staff where username='".$_SESSION['username'] ."'";
    $query=mysql_query($sql);
	
	if(mysql_num_rows($query)==0) {
			header("location:index.php");     
    } 
	else{
		$row=mysql_fetch_array($query);         
		$pass = $row["password"];
	}
	
	if(isset($_COOKIE['InputUsername'])){
		if( ($_SESSION['db_is_logged_in'] == true) && ( $_COOKIE["InputUsername"]!=$pass))
		{
			//header("location:index.php");
		}
	}
	
	if( ($_SESSION['db_is_logged_in'] == true)&&( $_SESSION['password']!=$pass))
	{
		header("location:index.php");
	}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Import</title>
	
    <link href="css/bootstrap.min.css" rel="stylesheet">
	<link href="css/signin.css" rel="stylesheet">
	<link href="css/bootstrap-combobox.css" media="screen" rel="stylesheet" type="text/css">
	
  </head>
  <body>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
	<script src="js/jquery.js"></script>
    <script src="js/bootstrap-datepicker.js"></script>  
	<script src="js/bootstrap-combobox.js" type="text/javascript"></script>
	
	<div class="container">
	 
		<h1 align="center"><span class="label label-info">NHẬP DỮ LIỆU TỪ EXCEL VÀO DATABASE</span></h1>
		<h4 align="center"><span class="label label-info"><i>(Dữ liệu thông tin sinh viên)</i></span></h4>
		<br/>
		<br/>
		
		
		<form action="helper/helper_student.php" method="post" enctype="multipart/form-data" class="form-signin" role="form">
			<div style="position:relative;">
				<a class='btn btn-primary' href='javascript:;'>
					Chọn tập tin...
					<input type="file" name="file" id="file" style='position:absolute;z-index:2;top:0;left:0;filter: alpha(opacity=0);-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";opacity:0;background-color:transparent;color:transparent;' name="file_source" size="40"  onchange='$("#upload-file-info").html($(this).val());'>
				</a>
				&nbsp;
				<span class='label label-info' id="upload-file-info"></span>
			</div>
			
			</br>
			
			
			<?php
				function query_sql($sql)
				{
					$result = mysql_query($sql);

					if (!$result) {
						echo "Could not successfully run query ($sql) from DB: " . mysql_error();
						exit;
					}

					if (mysql_num_rows($result) == 0) {
						echo "No rows found, nothing to print so am exiting";
						exit;
					}
					return $result;
				}
				
				$conn = mysql_connect("localhost", "root", "");
				mysql_set_charset('utf8',$conn);
				if (!$conn) {
					echo "Unable to connect to DB: " . mysql_error();
					exit;
				}

				if (!mysql_select_db("opensisdata")) {
					echo "Unable to select opensisdata: " . mysql_error();
					exit;
				}
			?>
			
			 
			<div class="control-group">	
			  <h4><span class="label label-info">Chọn Chương Trình Đào Tạo</span></h4>
              <div class="form-control">
				<?php	
					echo "<select required='required' name='schoolid'>";	
					echo "<option></option>";				
					/**____________________ Get and insert Staff ____________________**/
						$sql = "SELECT * FROM schools";
						$result = query_sql($sql);
						
						$student_enrollment_id = 0;
						while ($data = mysql_fetch_assoc($result)) {
							$_school_id = $data["id"];
							$_syear = $data["syear"];
							$_title = $data["title"];
							//echo '<p>' .'SCHOOL ID: ' .$_school_id .'</p>';
							//echo '<p>' .'SYEAR: ' .$_syear .'</p>';
							
							echo "<option value='" .$_school_id ."'>" .$_title ."</option>";
						}
					echo "</select>";
				?>       
            </div>
			  
			<div class="control-group">	
			  <h4><span class="label label-info">Chọn Lịch Giảng Dạy</span></h4>
              <div class="form-control">
				<?php	
					echo "<select required='required' name='calendarid'>";	
					echo "<option></option>";				
					/**____________________ Get and insert Staff ____________________**/
						$sql = "SELECT * FROM attendance_calendars";
						$result = query_sql($sql);
						
						$student_enrollment_id = 0;
						while ($data = mysql_fetch_assoc($result)) {
							$_school_id = $data["id"];
							$_calendar_id = $data["calendar_id"];
							$_title = $data["title"];
							//echo '<p>' .'SCHOOL ID: ' .$_school_id .'</p>';
							//echo '<p>' .'SYEAR: ' .$_syear .'</p>';
							
							echo "<option value='" .$_calendar_id ."'>" .$_title ."</option>";
						}
					echo "</select>";
				?>       
            </div>

			
			
			</br>
			  
			<input type="text" name = "_start_date" class="form-control" placeholder="Ngày vào trường" id="_start_date" required autofocus>
			
            </div>

			
			
			</br>
			<button class="btn btn-success" type="submit" name="submit">Lưu vào database</button>
		</form>
    </div>
	
   
      

	<script>
		$(function(){
			window.prettyPrint && prettyPrint();
			$('#_start_date').datepicker({
				format: 'yyyy-mm-dd',
                todayBtn: 'linked'
			});      
		});
	</script>

	<script type="text/javascript">
      //<![CDATA[
        $(document).ready(function(){
          $('.combobox').combobox()
        });
      //]]>
    </script>
  </body>
</html>